import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'
import DashboardView from '../views/DashboardView.vue'
import UsersView from '../views/UsersView.vue'
import FoodsView from '../views/FoodsView.vue'
import RecipesView from '../views/RecipesView.vue'
import DietRecordsView from '../views/DietRecordsView.vue'
import NutritionView from '../views/NutritionView.vue'
import SettingsView from '../views/SettingsView.vue'
import NotFoundView from '../views/NotFoundView.vue'
import { setupRouteGuards } from './guard'

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: LoginView,
    meta: { requiresAuth: false }
  },
  {
    path: '/',
    name: 'home',
    redirect: { name: 'dashboard' }
  },
  {
    path: '/dashboard',
    name: 'Dashboard',
    component: DashboardView,
    meta: { requiresAuth: true }
  },
  {
    path: '/users',
    name: 'Users',
    component: UsersView,
    meta: { 
      requiresAuth: true,
      title: '用户管理',
      permission: ''
    }
  },
  {
    path: '/foods',
    name: 'Foods',
    component: FoodsView,
    meta: { 
      requiresAuth: true,
      title: '食物数据库',
      permission: ''
    }
  },
  {
    path: '/recipes',
    name: 'Recipes',
    component: RecipesView,
    meta: { 
      requiresAuth: true,
      title: '食谱管理'
    }
  },
  {
    path: '/diet-records',
    name: 'DietRecords',
    component: DietRecordsView,
    meta: { 
      requiresAuth: true,
      title: '饮食记录'
    }
  },
  {
    path: '/nutrition',
    name: 'Nutrition',
    component: NutritionView,
    meta: { 
      requiresAuth: true,
      title: '营养分析'
    }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: SettingsView,
    meta: { 
      requiresAuth: true,
      title: '系统设置'
    }
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: NotFoundView,
    meta: { requiresAuth: false }
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

// 设置路由守卫
setupRouteGuards(router)

export default router
